#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
    int n, m, i, j;
    int sum = 0;
    int arr1[1000] = { 0 };
    int arr2[1000] = { 0 };
    int arr3[1000][1000] = { 0 };
    scanf("%d %d", &n, &m);
    for (i = 0; i < m; i++)
    {
        scanf("%d", &arr1[i]);
    }
    for (i = 0; i < m; i++)
    {
        scanf("%d", &arr2[i]);
    }
    for (i = 0; i < n; i++)
    {
        sum = 0;
        for (j = 0; j < m; j++)
        {
            scanf("%d", &arr3[i][j]);

            if (arr3[i][j] == arr2[j])
            {
                sum += arr1[j];
            }
        }
        printf("%d\n", sum);
    }
    return 0;
}